package com.rtx.wms.std.validation.po;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.stereotype.Component;

import com.rtx.api.annotation.DataSourceAnnotation;
import com.rtx.wms.std.common.bean.Codelkup;
import com.rtx.wms.std.common.bean.WmsConstant;
import com.rtx.wms.std.erpconfig.bean.RtxErpConfig;
import com.rtx.wms.std.po.bean.ApiPo;
import com.rtx.wms.std.po.bean.ApiPodetail;
import com.rtx.wms.std.sku.bean.po.Sku;
import com.rtx.wms.std.validation.BaseValidation;

@Component
public class PoCheck extends BaseValidation{

	/**
	 * 常规校验
	 */
	@DataSourceAnnotation
	public void  checkEnterpriseConfig(String datasourekey,ApiPo po) {
		Set<String> whseidSet = new HashSet<>();
		
		//校验单据类型转换
		Codelkup potype = validationCodelkup(WmsConstant.ENTERPRISE,po.getPotype(),"POTYPE",true);
		po.setPotyeConfig(potype);
		
		for(ApiPodetail podetail:po.getPodetail()) {
			List<RtxErpConfig> configList =	validationErpConfig(WmsConstant.ENTERPRISE, podetail.getRtxwerks(), podetail.getRtxlgort());
			po.setWhseid(configList.get(0).getWmwhse());
			whseidSet.add(configList.get(0).getWmwhse());
			
			Sku sku = validationSku(WmsConstant.ENTERPRISE, podetail.getStorerkey(), podetail.getSku(), true);
			podetail.setSkuentity(sku);
		}
		
		if(whseidSet.size()>1) {
			throw new RuntimeException("明细中工厂库存地在工厂库存地中只能wms一个仓库");
		}
		
	}
	
	
}
